package com.citcc.api.netty.server;


import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

public class TerminalAddressMap {

    public static Map<String,String> terminalAddressMap=null;//应改为concurrentHashmap以解决多线程冲突

    public static Map<String, String> getAddressHashMap() {
        return terminalAddressMap;
    }

    public static String getTerminalNoByAdd(String add){
        if(terminalAddressMap==null||terminalAddressMap.isEmpty()){
            return null;
        }
        return terminalAddressMap.get(add);
    }
    public static void addAddress(String add,String terminal){
        if(terminalAddressMap==null){
        	terminalAddressMap=new ConcurrentHashMap<>(100);
        }
        terminalAddressMap.put(add,terminal);
    }
    public static int removeTerminalNoByName(String add){
        if(terminalAddressMap.containsKey(add)){
        	terminalAddressMap.remove(add);
            return 0;
        }else{
            return 1;
        }
    }
    
    public static int getNum(){
    	return terminalAddressMap.size();
    }
    
    public static void main(String[] args) {
    	if(TerminalAddressMap.terminalAddressMap !=null){
    		System.out.println(getNum());
    	}else{
    		System.out.println(0);
    	}
		
	}
    
}
